package com.cy.pj.sys.service.impl;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.annotation.RequiredTime;
import com.cy.pj.sys.dao.SysLogDao;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogDao sysLogDao;


    @Async//描述该方法为一个一步切入点方法，这个方法执行时，
    // 底层会在一个新的线程中执行
    @Override
    public void saveLog(SysLog sysLog) {
        //System.out.println("----->"+Thread.currentThread().getName());
        sysLogDao.insertLogs(sysLog);
    }


    @Transactional(
            readOnly = true,//开启只读
            timeout = 30,//超时响应（s）
            isolation = Isolation.READ_COMMITTED,//开启事务隔离级别（读已提交）
            rollbackFor = RuntimeException.class//触发回滚
    )//事务切入点方法,进行事务控制
    @RequiredLog(operation = "Delete")
    @Override
    public int deleteById(Long... ids) {
        int rows=sysLogDao.deleteLogs(ids);
        return rows;
    }

    @RequiredLog(operation = "查询操作")//由此注解描述日志切入点方法
    @Override
    public SysLog findById(Long id) {
        SysLog log=sysLogDao.selectById(id);
        return log;
    }

    @RequiredTime
    @RequiredLog(operation = "查询操作")
    @Override
    public List<SysLog> findLogs(SysLog sysLog) {
        //System.out.println("----->"+Thread.currentThread().getName());
        List<SysLog> list=sysLogDao.selectLogs(sysLog);
        return list;
    }
}
